"""
    提供 logger 对象。
    > 其他任何 "libs" 模块都应使用此模块的 "logger" 来打印日志。

    Tip:
        移除 `logging` 改用 `loguru.logger`
"""
import wrapt
from loguru import logger


class Logger:
    def __init__(self, name):
        self.__log = logger.bind(name=name)
        self.__log.add(
            sink=f"{name}.log",
            format="{time} | {level} | {message}",
            rotation="1 week",
        )

    def __call__(self, func):
        @wrapt.decorator
        def wrapper(wrapped, instance, args, kwargs):
            resp = wrapped(*args, **kwargs)
            self.info(f"{wrapped.__name__}|=> {resp}")
            return resp
        return wrapper(func)

    @property
    def info(self):
        return self.__log.info

    @property
    def warn(self):
        return self.__log.warn

    @property
    def error(self):
        return self.__log.error

    @property
    def debug(self):
        return self.__log.debug


__all__ = [
    'Logger',
]
